

/*---------------------------------------------------------
   Initializes the effect. The data is a table of data 
   which was passed from the server.
---------------------------------------------------------*/
function EFFECT:Init( data )

	self.LifeTime = CurTime() + math.Rand( 10, 20 )
	self.EffectTime = CurTime() + (math.Rand( 2,4 ))
	self.Rand = math.random(1,4)

	local count = table.Count( VehicleGibs )
	local model = VehicleGibs[ math.random( 1,count ) ]
	if (model == nil) then model = "models/props_c17/oildrumchunk01d.mdl" end

	self:SetModel( model )
	self:PhysicsInit( SOLID_VPHYSICS )
	self:SetMoveType( MOVETYPE_VPHYSICS )
	self:SetSolid( SOLID_VPHYSICS ) 
	self:SetPos(data:GetOrigin() + (VectorRand() * math.random( -16, 16 )))
	local phys = self:GetPhysicsObject()
	
	if (!phys:IsValid()) then
		self:Remove()
		print("Error! "..model.." is not a valid prop model!\n")
	end
	
	if ( phys && phys:IsValid() ) then
	
		phys:Wake()
		phys:SetAngle( Angle( math.Rand(0,359), math.Rand(0,359), math.Rand(0,359) ) )
		phys:SetVelocity((Vector(0,0,5) * math.Rand( 20, 140 )) + (Vector(math.random(-300,300),math.random(-300,300),math.random(-100,100))))
		phys:AddAngleVelocity(Angle(math.random(-250,250),math.random(-250,250),math.random(-250,250)))
	
	end
	
	if self.Rand == 4 then
		self.Emitter = ParticleEmitter( self:GetPos() )
	end
	
end


/*---------------------------------------------------------
   THINK
   Returning false makes the entity die
---------------------------------------------------------*/
function EFFECT:Think( )

	if self.Rand == 4 then
		if self.EffectTime >= CurTime() then
			for i=1,math.random(1,3) do
		
				local particle = self.Emitter:Add("particles/smokey", self:GetPos() + (VectorRand()*math.random(-3,3)))

				particle:SetVelocity(Vector(0,0,-1))
				particle:SetDieTime( math.random(5,15)/10 )
				particle:SetStartAlpha( math.Rand( 90, 110 ) )
				particle:SetEndAlpha(1)
				particle:SetStartSize( math.Rand( 3, 5 ) )
				particle:SetEndSize( math.Rand( 1, 2 ) )
				particle:SetRoll( math.Rand( -95, 95 ) )
				particle:SetRollDelta( math.Rand( -0.12, 0.12 ) )
				local randy = math.random(10,50)
				particle:SetColor( randy,randy,randy ) //lols
				
			end
		end
	end

	if self.LifeTime >= CurTime() then
		return true
	else
		if self.Rand == 4 then
			self.Emitter:Finish()
		end
		return false
	end
end


/*---------------------------------------------------------
   Draw the effect
---------------------------------------------------------*/
function EFFECT:Render()

	self:DrawModel()

end



